package com.shuqi.model.parse.parser;

import java.util.ArrayList;
import java.util.List;

import org.xml.sax.Attributes;

import com.shuqi.model.bean.SyncBookMarkInfo;
import com.shuqi.model.bean.SyncBookMarksData;
import com.shuqi.model.parse.HandlerBase;

public class SyncBookMarksParser extends HandlerBase {

    private SyncBookMarksData bookMarksData;

    private List<SyncBookMarkInfo> list;

    @Override
    public Object getParsedData() {
        return bookMarksData;
    }

    @Override
    public void startElement(String uri, String localName, String qName, Attributes attributes) {
        if ("Body".equals(localName)) {
            bookMarksData = new SyncBookMarksData();
        } else if ("Result".equals(localName)) {
            bookMarksData.setCode(isNull(attributes, "code"));
            bookMarksData.setMessage(isNull(attributes, "message"));
        } else if ("BookMarks".equals(localName)) {
            list = new ArrayList<SyncBookMarkInfo>();
            bookMarksData.setList(list);
        } else if ("BookMark".equals(localName)) {
            SyncBookMarkInfo info = new SyncBookMarkInfo();
            info.setPlatform(isNull(attributes, "source"));
            info.setBookId(isNull(attributes, "bookId"));
            info.setSourceId(isNull(attributes, "sourceId"));
            info.setChapterId(isNull(attributes, "chapterId"));

            info.setBookName(isNull(attributes, "bookName"));
            info.setChapterName(isNull(attributes, "chapterName"));
            info.setAuthor(isNull(attributes, "author"));
            info.setImgUrl(isNull(attributes, "imgUrl"));

            info.setNumChapter(isNull(attributes, "numchapter"));
            info.setParam1(isNull(attributes, "param1"));
            info.setParam2(isNull(attributes, "param2"));
            info.setPercent(isNull(attributes, "percent"));

            // info.setSmCoverIsOpen(isNull(attributes, ""));
            info.setSqCoverIsOpen("1".equals(isNull(attributes, "cr_cover_isopen")));

            info.setUpdateTime(isNull(attributes, "updateTime"));
            list.add(info);
        }
    }
}
